package com.nulldev.util.networking.rudp.util;

import java.util.Stack;

public class SizedStack<T> extends Stack<T> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 8469852447990584187L;
	private int maxSize;

	public SizedStack(int size) {
		super();
		this.maxSize = size;
	}

	public int getMaxSize() {
		return maxSize;
	}

	@Override
	public T push(T object) {
		// If the stack is too big, remove elements until it's the right size.
		while (this.size() > maxSize) {
			this.remove(0);
		}
		return super.push(object);
	}
}
